import React, { ReactNode } from 'react'
import { Navigate, RouteObject } from 'react-router-dom'
import AuthRoutes from '@/components/auth-routes'
import { RoutesPath } from '@/global/constant'

const Login = React.lazy(() => import('@/views/login'))
const ForgetPwd = React.lazy(() => import('@/views/forget-pwd'))
const Main = React.lazy(() => import('@/views/main'))
const Dashboard = React.lazy(() => import('@/views/main/c-views/dashboard'))
const NotFound = React.lazy(() => import('@/views/not-found'))

// 动态路由
// 系统管理
const System = <Navigate to="/main/system/userList" />
const UserList = React.lazy(
  () => import('@/views/main/c-views/system/user-list')
)
const RoleList = React.lazy(
  () => import('@/views/main/c-views/system/role-list')
)
const MenuList = React.lazy(
  () => import('@/views/main/c-views/system/menu-list')
)
const Banned = React.lazy(() => import('@/views/main/c-views/system/banned'))
// 系统日志
const SystemLog = <Navigate to="/main/system/log/login" />
const LoginList = React.lazy(
  () => import('@/views/main/c-views/system/system-log/login-list')
)
const OperationList = React.lazy(
  () => import('@/views/main/c-views/system/system-log/operation-list')
)
// 敏感词管理
const SystemSensitive = <Navigate to="/main/system/sensitive/config" />
const UpdateConfig = React.lazy(
  () => import('@/views/main/c-views/system/sensitive/update-config')
)
const CustomRule = React.lazy(
  () => import('@/views/main/c-views/system/sensitive/custom-rule')
)
const Lexicon = React.lazy(
  () => import('@/views/main/c-views/system/sensitive/lexicon')
)
// 未决定
const AddressList = React.lazy(
  () => import('@/views/main/c-views/system/address-list')
)
// 分类管理
const Classify = <Navigate to="/main/classify" />
const ClassifyQuestion = React.lazy(
  () => import('@/views/main/c-views/classify/question')
)
// 题库管理
const QuestionDir = <Navigate to="/main/question" />
const QuestionList = React.lazy(
  () => import('@/views/main/c-views/question-manage/question-list')
)
const QuestionInfo = React.lazy(
  () => import('@/views/main/c-views/question-manage/question-info')
)
// 活动列表
const Activity = <Navigate to="/main/activity" />
const ActivityList = React.lazy(
  () => import('@/views/main/c-views/activity/activity-list')
)
// 积分管理
const Integral = <Navigate to="/main/integral" />
const IntegralDetail = React.lazy(
  () => import('@/views/main/c-views/integral/detail-list')
)
const IntegralTask = React.lazy(
  () => import('@/views/main/c-views/integral/task-list')
)
const IntegralShop = React.lazy(
  () => import('@/views/main/c-views/integral/shop-list')
)
const IntegralConvert = React.lazy(
  () => import('@/views/main/c-views/integral/convert-list')
)
// 签到管理
const Sign = <Navigate to="/main/sign" />
const SignContinuousReward = React.lazy(
  () => import('@/views/main/c-views/sign/continue-reward')
)
const SignDailyAttendance = React.lazy(
  () => import('@/views/main/c-views/sign/daily-attendance')
)

// 映射对象：path 对应  组件
// 在最后一步是只有路由的path没有组件的，我们需要根据path添加对应的路由组件，所以就有了下面的映射表
export const RoutesToModules: { [key in string]: ReactNode } = {
  [RoutesPath.System]: System,
  [RoutesPath.UserList]: <UserList />,
  [RoutesPath.RoleList]: <RoleList />,
  [RoutesPath.MenuList]: <MenuList />,
  [RoutesPath.Banned]: <Banned />,
  [RoutesPath.SystemLog]: SystemLog,
  [RoutesPath.LoginList]: <LoginList />,
  [RoutesPath.OperationList]: <OperationList />,
  [RoutesPath.SystemSensitive]: SystemSensitive,
  [RoutesPath.UpdateConfig]: <UpdateConfig />,
  [RoutesPath.Lexicon]: <Lexicon />,
  [RoutesPath.CustomRule]: <CustomRule />,
  [RoutesPath.AddressList]: <AddressList />,
  [RoutesPath.Classify]: Classify,
  [RoutesPath.ClassifyQuestion]: <ClassifyQuestion />,
  [RoutesPath.QuestionDir]: QuestionDir,
  [RoutesPath.QuestionList]: <QuestionList />,
  [RoutesPath.QuestionInfo]: <QuestionInfo />,
  [RoutesPath.Activity]: Activity,
  [RoutesPath.ActivityList]: <ActivityList />,
  [RoutesPath.Integral]: Integral,
  [RoutesPath.IntegralDetail]: <IntegralDetail />,
  [RoutesPath.IntegralTask]: <IntegralTask />,
  [RoutesPath.IntegralShop]: <IntegralShop />,
  [RoutesPath.IntegralConvert]: <IntegralConvert />,
  [RoutesPath.Sign]: Sign,
  [RoutesPath.SignContinuousReward]: <SignContinuousReward />,
  [RoutesPath.SignDailyAttendance]: <SignDailyAttendance />
}
const UserListConfig: RouteObject = {
  path: RoutesPath.UserList
}
const RoleListConfig: RouteObject = {
  path: RoutesPath.RoleList
}
const MenuListConfig: RouteObject = {
  path: RoutesPath.MenuList
}
const BannedConfig: RouteObject = {
  path: RoutesPath.Banned
}
const LoginListConfig: RouteObject = {
  path: RoutesPath.LoginList
}
const OperationListConfig: RouteObject = {
  path: RoutesPath.OperationList
}
const UpdateConfigConfig: RouteObject = {
  path: RoutesPath.UpdateConfig
}
const LexiconConfig: RouteObject = {
  path: RoutesPath.Lexicon
}
const CustomRuleConfig: RouteObject = {
  path: RoutesPath.CustomRule
}
const AddressListConfig: RouteObject = {
  path: RoutesPath.AddressList
}
const ClassifyQuestionConfig: RouteObject = {
  path: RoutesPath.ClassifyQuestion
}
const QuestionListConfig: RouteObject = {
  path: RoutesPath.QuestionList
}
const QuestionInfoConfig: RouteObject = {
  path: RoutesPath.QuestionInfo
}
const ActivityListConfig: RouteObject = {
  path: RoutesPath.ActivityList
}
const IntegralDetailConfig: RouteObject = {
  path: RoutesPath.IntegralDetail
}
const IntegralTaskConfig: RouteObject = {
  path: RoutesPath.IntegralTask
}
const IntegralShopConfig: RouteObject = {
  path: RoutesPath.IntegralShop
}
const IntegralConvertConfig: RouteObject = {
  path: RoutesPath.IntegralConvert
}
const SignContinueRewardConfig: RouteObject = {
  path: RoutesPath.SignContinuousReward
}
const SignDailyAttendanceConfig: RouteObject = {
  path: RoutesPath.SignDailyAttendance
}
// 保存所有的动态组件，用户登录后从这里去匹配自己有权限查看的页面
export const otherRoutes: RouteObject[] = [
  UserListConfig,
  RoleListConfig,
  MenuListConfig,
  BannedConfig,
  LoginListConfig,
  OperationListConfig,
  UpdateConfigConfig,
  LexiconConfig,
  CustomRuleConfig,
  AddressListConfig,
  ClassifyQuestionConfig,
  QuestionListConfig,
  QuestionInfoConfig,
  ActivityListConfig,
  IntegralDetailConfig,
  IntegralTaskConfig,
  IntegralShopConfig,
  IntegralConvertConfig,
  SignContinueRewardConfig,
  SignDailyAttendanceConfig
]

const routes: RouteObject[] = [
  {
    path: '/',
    element: <Navigate to="/main" />
  },
  {
    path: '/login',
    element: <Login />
  },
  {
    path: '/forget-pwd',
    element: <ForgetPwd />
  },
  {
    path: '/main',
    element: (
      <AuthRoutes>
        <Main />
      </AuthRoutes>
    ),
    children: [
      {
        path: '/main',
        element: <Navigate to="/main/dashboard" />
      },
      {
        path: '/main/dashboard',
        element: <Dashboard />
      }
      // {
      //   path: '/main/system/log',
      //   element: <Outlet />,
      //   children: [
      //     {
      //       path: '/main/system/log',
      //       element: <Navigate to="/main/system/log/login" />
      //     },
      //     {
      //       path: '/main/system/log/login',
      //       element: <LoginList />
      //     },
      //     {
      //       path: '/main/system/log/operation',
      //       element: <OperationList />
      //     }
      //   ]
      // }
    ]
  },
  {
    path: '*',
    element: <NotFound />
  }
]

export default routes
